<template>
	<view v-if="lists.length>0" class="index">
		<block v-for="(item,index) in lists" :key="index">
			<view class="commodity-item">
				<image class="commodity-img" src="/static/img/cut.png"></image>
				<view class="commodity-content">
					<text class="commodity-name">
						{{item.goods_name}}
					</text>
					<view class="">
						<text class="price">¥{{item.goods_id}}</text>
					</view>
					<text class="discount">{{discount}}折</text>
				</view>
			</view>
		</block>
	</view>
	<view v-else class="search-end">
		暂无搜索记录
	</view>
</template>

<script>
	export default {
		// props:["keyWords"],
		data() {
			return {
				goodsName: '',
				keyWords: "",
				lists: [],
				discount: 0,
				goods_price:0
			}
		},
		onLoad(e) {
			this.keyWords = e.keyWords
			// console.log(11111111, this.keyWords)
			this.getSearch()
		},
		mounted() {
			this.discount = (Math.floor(Math.random() * (100 - 10 + 1)) + 10) / 10
			this.goods_price = (Math.floor(Math.random() * (100 - 10 + 1)) + 10) * 100
		},
		methods: {
			//搜索的数据
			async getSearch() {
				console.log(444333111, this.keyWords)
				const res = await this.$myRequest({
					url: '/api/public/v1/goods/qsearch?query=' + this.keyWords
				})
				this.lists = res.data.message
				console.log(11122233311, this.lists)
			},
		},
	}
</script>

<style scoped>
	.search-end {
		text-align: center;
	}

	.commodity-item {
		width: 360rpx;
		padding-bottom: 20rpx;
		box-sizing: border-box;
	}

	.commodity-img {
		width: 100%;
		height: 375rpx;
		display: block;
		margin: auto;
	}

	.commodity-content {
		text-align: center;
	}

	.commodity-name {
		height: 80rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		color: #3333333;
		word-break: break-all;
		padding: 6rpx 20rpx;

	}

	.index {
		padding: 0 10rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
	}

	.discount {
		font-size: 24rpx;
		border-radius: 4rpx;
		border: 1px solid #FF3333;
		padding: 2rpx 10rpx;
		color: #FF3333;
	}
</style>
